package zxq.rollcall.course.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.BeanUtils;
import zxq.rollcall.course.entity.SystemUserTableEntity;
import zxq.rollcall.course.entity.enums.ERoles;
import zxq.rollcall.course.entity.query.StudentQuery;
import zxq.rollcall.course.entity.query.TeacherQuery;
import zxq.rollcall.course.mapper.SystemUserTableDao;
import zxq.rollcall.course.service.MPSystemUserTableService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * <p>
 * 系统用户表 服务实现类
 * </p>
 *
 * @author Yanghu
 * @since 2020-01-22
 */
@Service
public class SystemUserTableServiceDiy extends ServiceImpl<SystemUserTableDao, SystemUserTableEntity> implements MPSystemUserTableService {


    @Override
    public boolean saveStudentInfo(StudentQuery studentQuery) {
        SystemUserTableEntity userTableEntity = new SystemUserTableEntity();
        BeanUtils.copyProperties(studentQuery,userTableEntity);
        userTableEntity.setRoleId(ERoles.student);
        return save(userTableEntity);
    }

    @Override
    public boolean updateStudentInfo(Integer id, StudentQuery studentQuery) {
        SystemUserTableEntity userTableEntity = new SystemUserTableEntity();
        BeanUtils.copyProperties(studentQuery,userTableEntity);
        userTableEntity.setRoleId(ERoles.student);
        userTableEntity.setId(id);
        return updateById(userTableEntity);
    }

    @Override
    public boolean saveTeacherInfo(TeacherQuery teacherQuery) {
        SystemUserTableEntity userTableEntity = new SystemUserTableEntity();
        BeanUtils.copyProperties(teacherQuery,userTableEntity);
        userTableEntity.setRoleId(ERoles.teacher);
        return save(userTableEntity);
    }

    @Override
    public boolean updateTeacherInfo(Integer id, TeacherQuery teacherQuery) {
        SystemUserTableEntity userTableEntity = new SystemUserTableEntity();
        BeanUtils.copyProperties(teacherQuery,userTableEntity);
        userTableEntity.setRoleId(ERoles.teacher);
        userTableEntity.setId(id);
        return updateById(userTableEntity);
    }

    @Override
    public Integer queryClassId(Integer stuId) {

        return  getById(stuId).getClassId();
    }

    @Override
    public List<SystemUserTableEntity> queryStudent(Integer classId) {
        SystemUserTableEntity userTableEntity = new SystemUserTableEntity();
        userTableEntity.setClassId(classId);
        return list(new QueryWrapper<>(userTableEntity));
    }


}
